package zzh.com.myapplication;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import zzh.com.myapplication.apk.*;
import zzh.com.myapplication.apk.UpdateAppUtils;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //实例化更新工具
        DownLoadService service = new DownLoadService();
        service.startDownLoad();
        // UpdateAppUtils.getUtlis(this).downloadApp();
    }

    /**
     * 得到应用程序的版本号名 VersionName
     *
     * @param ct Context上下文
     */
    public static String getVersionName(Context ct) {
        try {
            // 管理手机的APP
            PackageManager packageManager = ct.getPackageManager();
            // 得到APP功能清单文件
            PackageInfo info = packageManager.getPackageInfo(ct.getPackageName(), 0);
            return info.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 得到应用程序的版本 code
     *
     * @param ct Context上下文
     */
    public static int getVerCode(Context ct) {
        int verCode = -1;
        try {
            // 管理手机的APP
            PackageManager packageManager = ct.getPackageManager();
            // 得到APP功能清单文件
            PackageInfo info = packageManager.getPackageInfo(ct.getPackageName(), 0);
            return info.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return verCode;
    }

}
